<?php
App::uses('AppController', 'Controller');

class //NameClass//Controller extends AppController {
    public $uses = array(//import_header//);
    public $helpers = array('Html','Form');

    public $paginate = array(
            'limit' => 10
    );
    
    public function index() {
//header_index//   
        $this->set('cakeDescription','//submenu//');
        $this->set('title_for_layout','//submenu// Index');
        $this->set('menu', '//menu//');
        $this->set('submenu', '//submenu//');
        
    }
    
    public function create() {
//ref_header//
        $this->set('cakeDescription','//submenu//');
        $this->set('title_for_layout','//submenu// Create');
        $this->set('menu', '//menu//');
        $this->set('submenu', '//submenu//');        
    }
    
    public function save() {
    Configure::write('debug', 0);
            $this->layout = 'ajax';
            $this->autoRender = false;
        $this->//Header//->create();
        $this->//Header//->set(
            array(
//py_save_header//
            )
        );
        if($this->//Header//->save()){
            
            $id = $this->//Header//->getLastInsertID();
            $end = $_POST['items'];
            for($pos = 0;$pos<$end;$pos++){
                $this->//Detail//->create();
                $this->//Detail//->set(
                    array(
                        '//relation//' => $id,
//py_save_detail//
                    )
                );
                $this->//Detail//->save();
            }     
        }
    }   
        
    public function view($id = null) {
        $//header// = $this->//Header//->read(null, $id);
        //ref_header//
        $//details//=$this->//Detail//->find('all',array('conditions'=>array('//relation//'=>$//header//['//Header//']['id'])));  
        
        $this->set('//header//', $//header//);      
        $this->set('//details//', $//details//);    
        $this->set('cakeDescription','//submenu//');
        $this->set('title_for_layout','//submenu// View');
        $this->set('menu', '//menu//');
        $this->set('submenu', '//submenu//');
	}
        
    public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->//Header//->id = $id;
		if (!$this->//Header//->exists()) {
			throw new NotFoundException(__('Invalid //NameClass//'));
		}
		if ($this->//Header//->delete()) {
			$this->Session->setFlash(__('//NameClass// deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('//NameClass// was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
?>